# -*- coding: utf-8 -*-
from datetime import timedelta

# def kwargs():
#     kwargs = {
#         "db": "ai_dwd",
#         "table": "yl_ml_clean_address_new_day",
#         "desc": "打上标签的全国日新增地址数据",
#         "taskid": "10050",
#         "ifprivacy": 0,
#         "warnignore": 0,
#     }
#     return kwargs
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator

from jms.aigroup.ai_dw.yl_ml_clean_address_day import ai_dw__yl_ml_clean_address_day

ai_dw__yl_ml_clean_address_new_day = SparkSqlOperator(
    task_id='ai_dw__yl_ml_clean_address_new_day',
    conn_id='spark_default',
    email=['yushuo@jtexpress.com','yl_bigdata@yl-scm.com'],
    pool_slots=4,
    # depends_on_past=True,  # 如果任务依赖于前一天的同名任务，则将 depends_on_past 设为 True
    task_concurrency=1,  # 如果任务不支持并发，则将 task_concurrency 设为 1
    name='ai_dw__yl_ml_clean_address_new_day_{{ execution_date | date_add(1) | cst_ds }}',  # yarn 任务名称
    sql='jms/aigroup/ai_dw/yl_ml_clean_address_new_day/execute.sql',
    yarn_queue='pyspark',
    driver_memory='4G' , 
    executor_memory='4G' , 
    executor_cores=4 , 
    num_executors=8 , 
    conf={
        'spark.executor.memoryOverhead'             : '2G' , 
          'spark.dynamicAllocation.enabled': 'true',
          'spark.shuffle.service.enabled': 'true',
        'spark.dynamicAllocation.maxExecutors'             : 10 , 
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',
          'spark.dynamicallocation.enabled': 'true',
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 120,
          'spark.sql.shuffle.partitions': 600
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions.pernode': 5000,
              'hive.exec.max.dynamic.partitions': 30000
              },
    execution_timeout=timedelta(hours=3),
    email_on_retry=True,
    # on_success_callback=yl_threeSegCodeOnSuccess(kwargs(), dingding_conn_id="dingding_ThreeSeg_etl_info"),
    # on_failure_callback=yl_threeSegCodeOnFailure(kwargs(), dingding_conn_id="dingding_ThreeSeg_etl_alert"),

)

# 设置依赖
ai_dw__yl_ml_clean_address_new_day << ai_dw__yl_ml_clean_address_day
